Skip to content

Eigenen Offline Debian Mirror erstellen

Ein offline Debian Mirror wird in Netzwerken eingesetzt, in denen Server oder Clients keinen direkten Zugang zum Internet haben, z. B. in einem sicheren LAN oder isolierten Netzwerken.

  1. Sicherheit zu erhöhen, indem Server und Clients keine externen Verbindungen benötigen.
  2. Internet-Traffic zu reduzieren, da Pakete lokal bereitgestellt werden.
  3. Verfügbarkeit sicherzustellen, selbst bei Ausfall der Internetverbindung.
  4. Kontrolle über Software-Versionen zu behalten, um Konsistenz in der Umgebung zu gewährleisten.

Voraussetzungen

  • Ein Server mit Debian (z.B. Bookworm).
  • Genügend Speicherplatz (je nach Bedarf können Mirrors mehrere 100 GB benötigen).
  • Funktionierender Apache2-Webserver.
  • Internetzugang, um den Mirror zu initialisieren.

Installiere die notwendigen Pakete

Installiere apt-mirror und andere benötigte Tools:

sudo apt update && sudo apt install apt-mirror apache2 gnupg

Konfiguriere apt-mirror

Die Konfigurationsdatei für apt-mirror befindet sich unter /etc/apt/mirror.list.

Unsere Beispielkonfiguration

Die Konfiguration erstellt Mirrors von Debian Bullseye und Debian Bookworm in den Architekturen amd64, armhf, armel und aarch64. Ebenfalls werden Mirrors von Linux Mint Faye und Linux Mint Ulyana in der Architektur amd64 gespiegelt. Auch für Raspbian Bullseye und Raspbian Bookworm wird für die Architekturen armhf und armel ein Spiegel erstellt.

# File: /etc/apt/mirror.list
############# Debian Bullseye #############
deb-amd64  http://deb.debian.org/debian/ bullseye main contrib non-free
deb-armhf  http://deb.debian.org/debian/ bullseye main contrib non-free
deb-armel  http://deb.debian.org/debian/ bullseye main contrib non-free
deb-aarch64 http://deb.debian.org/debian/ bullseye main contrib non-free

deb-amd64  http://deb.debian.org/debian/ bullseye-updates main contrib non-free
deb-armhf  http://deb.debian.org/debian/ bullseye-updates main contrib non-free
deb-armel  http://deb.debian.org/debian/ bullseye-updates main contrib non-free
deb-aarch64 http://deb.debian.org/debian/ bullseye-updates main contrib non-free

deb-amd64  http://security.debian.org/debian-security bullseye-security main contrib non-free
deb-armhf  http://security.debian.org/debian-security bullseye-security main contrib non-free
deb-armel  http://security.debian.org/debian-security bullseye-security main contrib non-free
deb-aarch64 http://security.debian.org/debian-security bullseye-security main contrib non-free

############# Debian Bookworm #############
deb-amd64  http://deb.debian.org/debian/ bookworm main contrib non-free
deb-armhf  http://deb.debian.org/debian/ bookworm main contrib non-free
deb-armel  http://deb.debian.org/debian/ bookworm main contrib non-free
deb-aarch64 http://deb.debian.org/debian/ bookworm main contrib non-free

deb-amd64  http://deb.debian.org/debian/ bookworm-updates main contrib non-free
deb-armhf  http://deb.debian.org/debian/ bookworm-updates main contrib non-free
deb-armel  http://deb.debian.org/debian/ bookworm-updates main contrib non-free
deb-aarch64 http://deb.debian.org/debian/ bookworm-updates main contrib non-free

deb-amd64  http://security.debian.org/debian-security bookworm-security main contrib non-free
deb-armhf  http://security.debian.org/debian-security bookworm-security main contrib non-free
deb-armel  http://security.debian.org/debian-security bookworm-security main contrib non-free
deb-aarch64 http://security.debian.org/debian-security bookworm-security main contrib non-free

############# Linux Mint (Faye, Ulyana) #############
deb-amd64  http://packages.linuxmint.com faye main upstream import
deb-amd64  http://packages.linuxmint.com ulyana main upstream import

############# Raspbian Bullseye #############
deb-armhf  http://raspbian.raspberrypi.org/raspbian/ bullseye main contrib non-free rpi
deb-armel  http://raspbian.raspberrypi.org/raspbian/ bullseye main contrib non-free rpi

############# Raspbian Bookworm #############
deb-armhf  http://raspbian.raspberrypi.org/raspbian/ bookworm main contrib non-free rpi
deb-armel  http://raspbian.raspberrypi.org/raspbian/ bookworm main contrib non-free rpi

############# Speicherort #############
set base_path    /var/www/html/mirror

Anpassen des Speicherpfads

Der Speicherpfad /var/www/html/mirror ist der Standard-Webroot von Apache2. Du kannst ihn anpassen, falls nötig.

Mirror-Synchronisation starten

Der Befehl apt-mirror startet die Synchronisation der definierten Spiegel. Je nach Anzahl und Größe der Repositories kann dies mehrere Stunden dauern.

sudo apt-mirror

Apache Webserver konfigurieren

Erstelle einen Virtual Host für deinen Mirror.

sudo vi /etc/apache2/sites-available/mirror.conf

<VirtualHost *:80>
    ServerName mirror.fritz.box
    DocumentRoot /var/www/html/mirror

    <Directory /var/www/html/mirror>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/mirror_error.log
    CustomLog ${APACHE_LOG_DIR}/mirror_access.log combined
</VirtualHost>
Aktiviere die Apache Konfiguration.

sudo a2ensite mirror.conf && sudo systemctl reload apache2

Hosts-Datei für lokale Namensauflösung

Damit der Mirror unter mirror.fritz.box erreichbar ist, füge ihn in deiner lokalen /etc/hosts Datei hinzu.

sudo vi /etc/hosts
192.168.x.x  mirror.fritz.box
Ersetze 192.168.x.x durch die IP-Adresse deines Servers.

Offline-GPG-Verifizierung für den lokalen Mirror einrichten

Wenn dein Mirror-Server offline betrieben wird, müssen die Clients den GPG-Schlüssel lokal beziehen können, da kein Zugriff auf Keyserver oder externe Quellen besteht. Dazu installieren wir die benötigten Keyring Pakete auf den lokalen Mirror Server und exportieren diese nach /var/www/html/mirror/keys/ wo diese öffentlich z.B. unter http://mirror.fritz.box/keys/debian-keyring.gpg erreichbar sind.

Debian Schlüssel exportieren

sudo sh -c 'gpg --no-default-keyring --keyring /usr/share/keyrings/debian-keyring.gpg --export --armor > /vol/box01/mirror/keys/debian-keyring-all.gpg'

Linux Mint Schlüssel exportieren

Zuerst laden wir uns das Keyring Archive von packages.linuxmint.com herunter und entpacken es.

cd /tmp/ && \
    wget http://packages.linuxmint.com/pool/main/l/linuxmint-keyring/linuxmint-keyring_2022.06.21.tar.gz && \
    tar xzvf linuxmint-keyring_2022.06.21.tar.gz

Dann importieren wir den Key in unseren Keyring

sudo gpg --import /tmp/linuxmint-keyring-2016.05.26ubuntu1/usr/share/keyrings/linuxmint-keyring.gpg

Mit gpg --list-keys können wir die Keys unseres Keyring anzeigen lassen.

sudo gpg --list-keys
/root/.gnupg/pubring.kbx
------------------------
pub   rsa4096 2016-05-24 [SC]
      302F0738F465C1535761F965A6616109451BBBF2
uid        [ unbekannt ] Linux Mint Repository Signing Key <root@linuxmint.com>
sub   rsa4096 2016-05-24 [E]

Nun kopieren wir den Keyring /root/.gnupg/pubring.kbx nach /usr/share/keyrings/linuxmint-keyring.gpg.

sudo cp /root/.gnupg/pubring.kbx /usr/share/keyrings/linuxmint-keyring.gpg

Nun exportieren wir den /usr/share/keyrings/linuxmint-keyring.gpg in unser öffentliches Verzeichnis.

sudo sh -c 'gpg --no-default-keyring --keyring /usr/share/keyrings/linuxmint-keyring.gpg --export --armor > /vol/box01/mirror/keys/linuxmint-keyring.gpg'

Raspbian Schlüssel exportieren

Zuerst laden wir uns den Key von raspbian.raspberrypi.org herunter.

cd /tmp/ && \
    wget http://raspbian.raspberrypi.org/raspbian.public.key

Dann importieren wir den Key in unseren Keyring

sudo gpg --import  raspbian.public.key

Mit gpg --list-keys können wir die Keys unseres Keyring anzeigen lassen.

sudo gpg --list-keys

/root/.gnupg/pubring.kbx
------------------------
pub   rsa2048 2012-10-25 [SC] [verfallen: 2022-09-16]
      F7E5D48CF5F4061684A626200A3F5E91F8364EDF
uid        [ verfallen ] Andrew DeMaria (Work) <ademaria@redhat.com>
uid        [ verfallen ] Andrew DeMaria (Colorado Hacker) <lostonamountain@gmail.com>

pub   rsa2048 2012-04-01 [SC]
      A0DA38D0D76E8B5D638872819165938D90FDDD2E
uid        [ unbekannt ] Mike Thompson (Raspberry Pi Debian armhf ARMv6+VFP) <mpthompson@gmail.com>
sub   rsa2048 2012-04-01 [E]

Nun kopieren wir den Keyring /root/.gnupg/pubring.kbx nach /usr/share/keyrings/raspbian-keyring.gpg.

sudo cp /root/.gnupg/pubring.kbx /usr/share/keyrings/raspbian-keyring.gpg

Nun exportieren wir den /usr/share/keyrings/raspbian-keyring.gpg in unser öffentliches Verzeichnis.

sudo sh -c 'gpg --no-default-keyring --keyring /usr/share/keyrings/raspbian-keyring.gpg --export --armor > /vol/box01/mirror/keys/raspbian-keyring.gpg'

Alle exportierten Schlüssel anzeigen lassen

ls -l /vol/box01/mirror/keys/
insgesamt 37768
-rw-r--r-- 1 root root 38660381 22. Dez 22:24 debian-keyring-all.gpg
-rw-r--r-- 1 root root     3098 22. Dez 22:47 linuxmint-keyring.gpg
-rw-r--r-- 1 root root     7563 22. Dez 23:17 raspbian-keyring.gpg

Schlüssel an die Clients verteilen

Um sicherzustellen, dass die Clients den lokalen Mirror vertrauen, musst du die heruntergeladenen GPG-Schlüssel den Clients bekannt machen.

Füge die Schlüssel direkt in eine APT-Konfigurationsdatei ein. Erstelle eine neue Datei in /etc/apt/trusted.gpg.d/, z. B. wie hier für Debian.

sudo wget http://mirror.fritz.box/keys/debian-keyring-all.gpg -O /etc/apt/trusted.gpg.d/debian-keyring-all.gpg

Für Linux Mint würde der Befehl so aussehen.

sudo wget http://mirror.fritz.box/keys/mint-keyring-all.gpg -O /etc/apt/trusted.gpg.d/mint-keyring-all.gpg

Für Rasbian nutzen wir diesen Befehl.

sudo wget http://mirror.fritz.box/keys/raspberrypi-keyring-all.gpg -O /etc/apt/trusted.gpg.d/raspberrypi-keyring-all.gpg

In der /etc/apt/sources.list des Client, muss dieser Key dann mit signed-by angegeben werden.

Hier eine Beispiel source.list für Debian Bookworm.

# Debian Bookworm Repositories für den lokalen Mirror
deb [trusted=yes signed-by=/etc/apt/trusted.gpg.d/debian-keyring-all.gpg] http://mirror.fritz.box/debian bookworm main contrib non-free
deb-src [trusted=yes signed-by=/etc/apt/trusted.gpg.d/debian-keyring-all.gpg] http://mirror.fritz.box/debian bookworm main contrib non-free

# Debian Bookworm Sicherheitsupdates
deb [trusted=yes signed-by=/etc/apt/trusted.gpg.d/debian-keyring-all.gpg] http://mirror.fritz.box/debian-security bookworm-security main contrib non-free
deb-src [trusted=yes signed-by=/etc/apt/trusted.gpg.d/debian-keyring-all.gpg] http://mirror.fritz.box/debian-security bookworm-security main contrib non-free

So sieht die source.list für Linux Mint Faye aus.

# Linux Mint Faye Repositories für den lokalen Mirror
deb [trusted=yes signed-by=/etc/apt/trusted.gpg.d/mint-keyring-all.gpg] http://mirror.fritz.box/mint faye main upstream import
deb-src [trusted=yes signed-by=/etc/apt/trusted.gpg.d/mint-keyring-all.gpg] http://mirror.fritz.box/mint faye main upstream import

# Linux Mint Faye Sicherheitsupdates
deb [trusted=yes signed-by=/etc/apt/trusted.gpg.d/mint-keyring-all.gpg] http://mirror.fritz.box/mint-security faye-security main upstream import
deb-src [trusted=yes signed-by=/etc/apt/trusted.gpg.d/mint-keyring-all.gpg] http://mirror.fritz.box/mint-security faye-security main upstream import

So sieht die source.list für LMDE 6 Faye aus.

# LMDE 6 Faye Repositories für den lokalen Mirror
deb [trusted=yes signed-by=/etc/apt/trusted.gpg.d/mint-keyring-all.gpg] http://mirror.fritz.box/packages.linuxmint.com faye main upstream import backport

# Debian Bookworm Repositories für den lokalen Mirror
deb [trusted=yes signed-by=/etc/apt/trusted.gpg.d/debian-keyring-all.gpg] http://mirror.fritz.box/debian bookworm main contrib non-free non-free-firmware
deb [trusted=yes signed-by=/etc/apt/trusted.gpg.d/debian-keyring-all.gpg] http://mirror.fritz.box/debian bookworm-updates main contrib non-free non-free-firmware
deb [trusted=yes signed-by=/etc/apt/trusted.gpg.d/debian-keyring-all.gpg] http://mirror.fritz.box/debian bookworm-security main contrib non-free non-free-firmware
deb [trusted=yes signed-by=/etc/apt/trusted.gpg.d/debian-keyring-all.gpg] http://mirror.fritz.box/debian bookworm-backports main contrib non-free non-free-firmware

So sieht die source.list für Raspbian Bookworm aus.

# Raspbian Bookworm Repositories für den lokalen Mirror
deb [trusted=yes signed-by=/etc/apt/trusted.gpg.d/raspberrypi-keyring-all.gpg] http://mirror.fritz.box/raspbian bookworm main contrib non-free
deb-src [trusted=yes signed-by=/etc/apt/trusted.gpg.d/raspberrypi-keyring-all.gpg] http://mirror.fritz.box/raspbian bookworm main contrib non-free

# Raspbian Bookworm Sicherheitsupdates
deb [trusted=yes signed-by=/etc/apt/trusted.gpg.d/raspberrypi-keyring-all.gpg] http://mirror.fritz.box/raspbian-security bookworm/updates main contrib non-free
deb-src [trusted=yes signed-by=/etc/apt/trusted.gpg.d/raspberrypi-keyring-all.gpg] http://mirror.fritz.box/raspbian-security bookworm/updates main contrib non-free

Den Mirror auf dem Cient prüfen

Nachdem wir auf dem Client die source.list auf dem lokalen Mirror umgestellt haben, können wir diesen wie folgt testen.

sudo apt update